import request from '../../utils/request'
import {requestString} from '../../utils/request'
import {download} from '../../utils/commons'

/**
 * 多条件分页查询结算单列表
 * @param cstId
 * @param page
 * @returns {Promise.<void>}
 */
export async function queryStatements({ stObjId ,status,stateno, customerno, minamount, maxamount, creator, stObj, beginTime, endTime, page}) {
    return request(apiPath.zbtim + "/api/statements", {
        method: 'get',
        data: { stObjId, status,stateno, customerno, minamount, maxamount, creator, stObj, beginTime, endTime, page: page.page, size: page.size}
    });
}


/**
 * 按供应商、订单id、费用类型查询订单费用列表
 *
 * @param
 * @return
 */
export async function queryStatetemntDetail(data) {
    return request(apiPath.zbtim + "/api/statement/detail", {
        method: 'get',
        data
    });
}

/**
 * 创建结算单
 *
 */
export async function createStatement(data) {
    return requestString(apiPath.zbtim + "/api/statement", {
        method: 'post',
        data
    });
}

/**
 * 结算单审批
 *
 */
export async function approvalStatement(data) {
    return request(apiPath.zbtim + "/api/statement" + id + "/approval", {
        method: 'post',
        data
    });
}


/**
 * 结算单付款
 *
 */
export async function payStatement(data) {
    return request(apiPath.zbtim + "/api/statement" + id + "/pay", {
        method: 'post',
        data
    });
}

/**
 * 结算单信息和结算单明细
 *
 * @param
 * @return
 */
export async function getStatement({id}) {
    return request(apiPath.zbtim + "/api/statement/"+ id, {
        method: 'get'
    });
}


/**
 * 结算单付款信息查询
 *
 * @param cstId
 * @return
 */
export async function queryPayStatement({id}) {
    return request(apiPath.zbtim + "/api/statement/"+ id + "/pay" , {
        method: 'get'
    });
}



/**
 * 更新结算单状态
 * @param params
 * @returns {Promise.<void>}
 */
export async function updateStatementStatus(data) {
    return request(apiPath.zbtim + "/api/statement"+ id + "/status", {
        method: 'post',
        data
    });
}



/**
 * 结算单审核信息列表查询
 * @param id
 * @returns {Promise.<void>}
 */
export async function queryApprovalStatement({id, page}) {
    return request(apiPath.zbtim + "/api/statement/"+ id + "/approval", {
        method: 'get',
        data: {id, page: page.page, size: page.size}
    });
}


/**
 * 导出excel
 * @param orderId
 * @returns {Promise.<void>}
 */
export async function generateStatement({id}) {
    let url =  apiPath.zbtim + "/api/" + id + "/export";
    download(url, {id: id, filename: '付款申请表'});

}